#!/bin/sh

war=yj-marktaskspool

/data/tomcat-7.0.82-yj-marktaskspool/bin/stop.sh
cd /data/tomcat-7.0.82-yj-marktaskspool/webapps/ && rm -rf ROOT
mv ~/"$war"*.war /data/tomcat-7.0.82-yj-marktaskspool/webapps/"$war".war
unzip /data/tomcat-7.0.82-yj-marktaskspool/webapps/"$war".war -d /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT
cd /data/tomcat-7.0.82-yj-marktaskspool/webapps/ &&  rm -rf "$war".war
rm -rf ~/"$war"*.war

env=$1
type=$2


if [ $env = "pro" ]; then
    cp -R /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/pro-SpringContext.xml /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/SpringContext.xml
    cp -R /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/pro-logback.xml /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/logback.xml

    if [ $type = "create" ]; then
        cp -R /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/pro-create-conf.properties /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/conf.properties
        cp -R /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/dubbo/notread-yj-task-dubbo-provider.xml /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/dubbo/yj-task-dubbo-provider.xml
    elif [ $type = "read" ]; then
        cp -R /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/pro-read-conf.properties /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/conf.properties
        cp -R /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/dubbo/read-yj-task-dubbo-provider.xml /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/dubbo/yj-task-dubbo-provider.xml
    elif [ $type = "save" ]; then
        cp -R /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/pro-save-conf.properties /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/conf.properties
        cp -R /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/dubbo/notread-yj-task-dubbo-provider.xml /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/dubbo/yj-task-dubbo-provider.xml
    elif [ $type = "savelog" ]; then
        cp -R /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/pro-savelog-conf.properties /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/conf.properties
        cp -R /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/dubbo/notread-yj-task-dubbo-provider.xml /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/dubbo/yj-task-dubbo-provider.xml
    else
        echo "不支持的启动实例类型，目前支持只【create/read/save】"
        exit 1
    fi

elif [ $env = "test" ]; then
    cp -R /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/test-SpringContext.xml /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/SpringContext.xml
    cp -R /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/test-conf.properties /data/tomcat-7.0.82-yj-marktaskspool/webapps/ROOT/WEB-INF/classes/conf.properties
else
    echo "不支持的环境类型，目前支持只【pro/test】"
    exit 1
fi

#启动tomcat
/data/tomcat-7.0.82-yj-marktaskspool/bin/startup.sh
